package com.ele.web;

import com.ele.pojo.Employee;
import com.ele.service.EmployeeService;
import com.ele.service.impl.EmployeeServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/addEmp")
public class AddEmpServlet extends HttpServlet {
    private EmployeeService employeeService = new EmployeeServiceImpl();
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 设置请求中数据的编码格式
        req.setCharacterEncoding("utf-8");

        String account = req.getParameter("account");
        String password = req.getParameter("password");
        String nickname = req.getParameter("nickname");
        String telephone = req.getParameter("telephone");
        String role = req.getParameter("role");
        int is_del = Integer.parseInt(req.getParameter("isDel"));
        // 封装
        Employee employee=new Employee();
        employee.setAccount(account);
        employee.setPassword(password);
        employee.setNickname(nickname);
        employee.setTelephone(telephone);
        employee.setRole(role);
        employee.setIsDel(is_del);
        System.out.println(employee);
        int b = this.employeeService.addEmp(employee);
        resp.getWriter().write(b+"");
    }
}

